package com.eckey.lab.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author: ChengLiang
 * @CreateTime: 2023-11-06  09:55
 * @Description: TODO
 * @Version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {

    private String code;

    private String msg;

    private T data;

    public static <T> Result buildResult(String code, String msg, T data) {
        return new Result(code, msg, data);
    }

    public static Result buildResultSuccess() {
        return new Result(com.eckey.lab.common.Constants.ResponseCode.SUCCESS.getCode(), com.eckey.lab.common.Constants.ResponseCode.SUCCESS.getMsg(), null);
    }

    public static <T> Result buildDataSuccess(T data) {
        return new Result(com.eckey.lab.common.Constants.ResponseCode.SUCCESS.getCode(), com.eckey.lab.common.Constants.ResponseCode.SUCCESS.getMsg(), data);
    }

    public static Result buildResultError() {
        return new Result(com.eckey.lab.common.Constants.ResponseCode.UN_ERROR.getCode(), com.eckey.lab.common.Constants.ResponseCode.UN_ERROR.getMsg(), null);
    }

    public static <T> Result buildDataError(T data) {
        return new Result(com.eckey.lab.common.Constants.ResponseCode.UN_ERROR.getCode(), Constants.ResponseCode.UN_ERROR.getMsg(), data);
    }

}
